import { Tween } from "../etc/Tween";
import DeadTransitionWindow_Generate from "../ui-generate/DeadTransitionWindow_generate";

export class DeadTransitionWindow extends DeadTransitionWindow_Generate {
    static startTransition(callback:Function){
        UIService.show(DeadTransitionWindow, callback)
    }

    private callback: Function

    private tween2: Tween<{t:number}> = new Tween({ t: 1 })
        .to({ t: 0 }, 1200)
        .onUpdate((obj) => {
            this.mask.renderOpacity = obj.t;
        })
        .onComplete(() => {
            UIService.hideUI(this)
        });

    private tween1: Tween<{t:number}> = new Tween({ t: 0 })
        .to({ t: 1 }, 500)
        .onStart(()=>{
            this.mask.renderOpacity = 0;
        })
        .onUpdate((obj) => {
            this.mask.renderOpacity = obj.t;
        })
        .onComplete(() => {
            this.callback()
        }).chain(this.tween2);

    protected onShow(callback: Function) {
        this.callback = callback
        this.tween1.start()
    }
}
